package com.workstudy.wstudy.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.workstudy.common.annotation.Log;
import com.workstudy.common.enums.BusinessType;
import com.workstudy.wstudy.domain.WstPostExamine;
import com.workstudy.wstudy.service.IWstPostExamineService;
import com.workstudy.common.core.controller.BaseController;
import com.workstudy.common.core.domain.AjaxResult;
import com.workstudy.common.utils.poi.ExcelUtil;
import com.workstudy.common.core.page.TableDataInfo;

/**
 * 岗位审核Controller
 * 
 * @author sun
 * @date 2021-04-07
 */
@Controller
@RequestMapping("/wstudy/examine")
public class WstPostExamineController extends BaseController
{
    private String prefix = "wstudy/examine";

    @Autowired
    private IWstPostExamineService wstPostExamineService;

    @RequiresPermissions("wstudy:examine:view")
    @GetMapping()
    public String examine()
    {
        return prefix + "/examine";
    }

    /**
     * 查询岗位审核列表
     */
    @RequiresPermissions("wstudy:examine:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WstPostExamine wstPostExamine)
    {
        startPage();
        List<WstPostExamine> list = wstPostExamineService.selectWstPostExamineList(wstPostExamine);
        return getDataTable(list);
    }

    /**
     * 导出岗位审核列表
     */
    @RequiresPermissions("wstudy:examine:export")
    @Log(title = "岗位审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WstPostExamine wstPostExamine)
    {
        List<WstPostExamine> list = wstPostExamineService.selectWstPostExamineList(wstPostExamine);
        ExcelUtil<WstPostExamine> util = new ExcelUtil<WstPostExamine>(WstPostExamine.class);
        return util.exportExcel(list, "examine");
    }

    /**
     * 新增岗位审核
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存岗位审核
     */
    @RequiresPermissions("wstudy:examine:add")
    @Log(title = "岗位审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WstPostExamine wstPostExamine)
    {
        return toAjax(wstPostExamineService.insertWstPostExamine(wstPostExamine));
    }

    /**
     * 修改岗位审核
     */
    @GetMapping("/edit/{postId}")
    public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
    {
        WstPostExamine wstPostExamine = wstPostExamineService.selectWstPostExamineById(postId);
        mmap.put("wstPostExamine", wstPostExamine);
        return prefix + "/edit";
    }

    /**
     * 岗位审核
     */
    @PostMapping("/query")
    @ResponseBody
    public AjaxResult query(Long postId)
    {
        WstPostExamine wstPostExamine = wstPostExamineService.selectWstPostExamineById(postId);
        return AjaxResult.success("成功",wstPostExamine);
    }

    /**
     * 修改保存岗位审核
     */
    @RequiresPermissions("wstudy:examine:edit")
    @Log(title = "岗位审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WstPostExamine wstPostExamine)
    {
        return toAjax(wstPostExamineService.updateWstPostExamine(wstPostExamine));
    }

    /**
     * 删除岗位审核
     */
    @RequiresPermissions("wstudy:examine:remove")
    @Log(title = "岗位审核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wstPostExamineService.deleteWstPostExamineByIds(ids));
    }
}
